home *** CD-ROM | disk | FTP | other *** search
- /* blockio.c - retrieve/update index blocks for BTREE */
- #include "stdio.h"
- #include "btree.h"
- #include "bt_macro.h"
-
- extern IX_DESC *pci ; /* refers to index descriptor */
- /* for current function call */
-
- extern BLOCK spare_block ; /* scratch block for splits and */
- /* compressing */
-
- RECPOS get_free() ;
-
- int init_bio() /* initialize blockio */
- {
- init_cache() ; /* init. cache buffers */
- }
-
-
- int retrieve_block(l,r,pb,current)
- /* retrieve an index block */
- int l ; /* index level of this block */
- RECPOS r ; /* block's location in index file */
- BLOCK *pb ; /* put it here */
- int current ; /* =1, put in cache */
- {
- if( chk_cache(l,r) != 0 ) /* look in cache first */
- get_cache(l,r,pb) ; /* there - get it */
- else
- { read_block(r,pb) ; /* not there - read it */
- pb->brec = r ;
- pb->lvl = l ;
- if( current ) /* current block for level l ? */
- put_cache(l,pb) ; /* yes - put in the cache */
- }
- return( IX_OK ) ;
- }
-
-
- int update_block(pb) /* update an index block in file */
- BLOCK *pb ; /* address of index block */
- {
- if( chk_cache(pb->lvl,pb->brec) != 0 )
- put_cache(pb->lvl,pb) ;
- write_block(pb->brec,pb) ;
- }
-
- int get_block(l,pb) /* allocate and set up a block */
- /* retrieve an index block */
- int l ; /* index level for this block */
- BLOCK *pb ; /* put it here */
- {
- RECPOS r ;
-
- r = get_free() ; /* allocate disk block */
- if( r == NULLREC )
- return( IX_FAIL ) ;
- pb->brec = r ; /* record block's file position */
- pb->lvl = l ; /* and it's level */
- return( IX_OK ) ;
- }
-
- int put_free(pb) /* return block to the free list */
- BLOCK *pb ;
- {
- scrub_cache(pb->brec) ; /* remove from cache */
- pb->lvl = FREE_LEVEL ; /*mark as free */
- write_free(pb->brec,pb) ;
- }
-
- int read_block(r,pb) /* read an index blocl */
- RECPOS r ; /* block's location in index file */
- BLOCK *pb ; /* store the block here */
- {
- int ret ;
-
- ret = read_if(r,pb, sizeof(BLOCK) ) ;
- return( ret ) ;
- }
-
-
- int write_block(r,pb) /* write an index block */
- RECPOS r ; /* block's location in index file */
- BLOCK *pb ; /* the data to write */
- {
- int ret ;
-
- ret = write_if(r,pb, sizeof(BLOCK) ) ;
- return( ret ) ;
- }
-
-
-